<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.3.4/gsap.min.js"></script>
    <style>
        ul,li{
        margin: 0;
        padding: 0;
        list-style: none;
        }
        .m-slide{
        width: 800px;
        height: 300px;
        overflow: hidden;
        position: relative;
        margin: 0 auto;
        }
        .m-slide ul {
        width: 500%;
        display: flex;
        margin-left: 0%;
        }
        .m-slide ul li{
        width: 100%;
        height: 300px;
        background: #ffaa88;
        }
        .m-slide ul.m-slide-dot{
        width: 200px;
        position: absolute;
        right: 44px;
        bottom: 20px;
        display: flex;
        }
        .m-slide ul.m-slide-dot li{
        height: 40px;
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 20px;
        margin-left: 10px;
        color: #ffffff;
        cursor: pointer;
        }
        .m-slide ul.m-slide-dot li.m-slide-dot-selected{
            background: #998811;
        }
    </style>
</head>
<body>
    <div class="m-slide">
        <ul>
          <li style="background:#ffaaee;">内容11</li>
          <li style="background:#ff3344;">内容22</li>
          <li style="background:#ff8899;">内容33</li>
          <li style="background:#ffeeaa;">内容44</li>
          <li style="background:#ffaaee;">内容11</li>
        </ul>
        <ul class="m-slide-dot">
          <li class="m-slide-dot-selected">1</li>
          <li>2</li>
          <li>3</li>
          <li>4</li>
        </ul>
      <div>
    <script>

        var ele = document.querySelector(".m-slide ul")
        var slideDotList = document.querySelectorAll(".m-slide-dot li")
        var currentIndex = 0
        slideDotList.forEach((item,index)=>{
            item.index = index
            item.onclick=function(){
                currentIndex = index
                animate(this.index)
            }
        })
        function animate(index) {
            var t2 = gsap.timeline()
            slideDotList.forEach(item=>{
                item.className = ''
            })
            if(index == slideDotList.length) {
                slideDotList[0].className = 'm-slide-dot-selected'
                return t2.to(ele,{x: -800*index,duration: 0.8},0.01).call(()=>{
                    var t3 = gsap.timeline()
                    t3.to(ele,{x:0,duration:0},0)
                })
            } else {
                slideDotList[index].className = 'm-slide-dot-selected'
                return t2.to(ele,{x: -800*index,duration: 0.8},0.01)
            }
        }
        let timer = setInterval(()=>{
            animate(currentIndex).call(()=>{
                currentIndex+=1
                if(currentIndex>slideDotList.length) {
                    currentIndex = 0
                }
            })
        },2000)
        
    </script>
</body>
</html>